package Ex2;

import java.io.File;
import java.util.StringTokenizer;


public class Q3 
{

	public static void main(String[] args) 
	{
		String repoPath = "/Users/itay/Desktop/ex2Input/aol.txt";
		File file = new File(repoPath);
		String doc = Q1.loadTextFromFile(file);
		
		String keyWord = "German";
		
		double tf = getTF(keyWord, doc);
		
		System.out.println("'" + keyWord + "' TF is: " + tf);
	}
	
	public static double getTF(String keyWord, String doc)
	{
		double totalWordsCount = 0;
		double keyWordCount = 0;
		
		StringTokenizer Tok = new StringTokenizer(doc, " \n\r");

        while (Tok.hasMoreElements())
        {
            if (keyWord.equalsIgnoreCase(Tok.nextElement().toString()))  
            {
            	keyWordCount++;
            }
            totalWordsCount++;
        }
        
		return (totalWordsCount == 0) ? 0 : (keyWordCount / totalWordsCount);
	}

}

